package com.ff.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ff.common.CustemException;
import com.ff.entity.Category;
import com.ff.entity.Dish;
import com.ff.mapper.CategoryMapper;
import com.ff.mapper.DishMapper;
import com.ff.mapper.SetmealMapper;
import com.ff.service.CategoryService;
import com.ff.service.DishService;
import com.ff.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {
    @Autowired
    DishService dishService;
    @Autowired
    SetmealService setmealService;
    @Override
    public void remove(Long id) {
        QueryWrapper queryWrapper=new QueryWrapper<Dish>();
        queryWrapper.eq("category_Id",id);
        if(dishService.count(queryWrapper)>0){
            throw new CustemException("该分类下链接了菜品不能删除");
        }
        if(setmealService.count(queryWrapper)>0){
            throw new CustemException("该分类下链接了套餐不能删除");
        }
        super.removeById(id);
    }

}
